package com.jsnkj.basic.fragment

import androidx.lifecycle.MutableLiveData
import com.jsnkj.basic.bean.ErrorEntity
import com.jsnkj.basic.bean.UserGroupCodeEntity
import com.jsnkj.basic.bean.UserLoginEntity
import com.jsnkj.basic.http.HttpApiService
import com.jsnkj.basic.mvvm.HttpViewModel
import com.yang.http.HttpRequest

class MineViewModel : HttpViewModel() {

    var postLoginResult: MutableLiveData<UserLoginEntity> = MutableLiveData()
    var errorResult: MutableLiveData<ErrorEntity> = MutableLiveData()
    /**
     * 获取用户信息
     */
    fun postAuthUserInfo() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postAuthUserInfo()
        }, onResult = { it ->
//            LogUtils.e("请求成功：$it")
            postLoginResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value =ErrorEntity.getInstance(code,msg)
            com.jsnkj.basic.util.LogUtils.e(" 获取用户信息 - onFailed: $code, $msg")
        }) {
            //LogUtils.e("请求成功", "postAppInit onComplete")
        }
    }


    var postUserGroupCodeResult: MutableLiveData<UserGroupCodeEntity> = MutableLiveData()

    fun postUserGroupCode() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postUserGroupCode()
        }, onResult = { it ->
//            LogUtils.e("请求成功：$it")
            postUserGroupCodeResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value =ErrorEntity.getInstance(code,msg)
            com.jsnkj.basic.util.LogUtils.e(" 获取用户信息 - onFailed: $code, $msg")
        }) {
            //LogUtils.e("请求成功", "postAppInit onComplete")
        }
    }
}